package com.hns.can.energy.web;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.energy.entity.AppOilPriceEntity;
import com.hns.can.energy.service.OilPriceService;
import com.hns.can.energy.vo.EnergyExportVo;
import com.hns.can.energy.vo.EnergyVo;
import com.hns.can.master.vo.CarPostDataVo;

import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.UtilString;

/**
 * 通过城市加载该城市的油价调整日期
 * @author:chenl
 * @email:370238764@qq.com
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/funEnergyPriceSet")
public class FunEnergyPriceController extends BaseController{
    
    @Autowired
    OilPriceService oilPriceService;
    

	/**
	 * 导出文件表头
	 */
	private final String[] tableHeaderNames={"省份","城市","调整日期","燃油种类","燃油价格"};
	/**
	 * 导出文件字段名
	 */
    private final String[] tableHeaderFields={"provinceId","cityId","adjustDate","oilType","price"};

    
    /**
     * 
     * @param city
     * @param response
     * @param request
     * @author:Lan
     * @return 
     * @email:763836737@qq.com
     * @创建日期:2014-9-2
     * @功能说明：油价调整日期查询
     */
    @RequestMapping("/selectEnergyTime")
    @ResponseBody
    public Object selectEnergyTime(String cityId) throws Exception{
        List<AppOilPriceEntity> list=oilPriceService.selectEnergyTime(cityId);
        return this.getReturnResult(list);
    }
    
    
    /**
     * 
     * @param vo
     * @return
     * @author:chenl
     * @return 
     * @email:370238764@qq.com
     * @创建日期:2016-9-5
     * @功能说明：油价信息查询
     */
    @RequestMapping("/searchEnergyInfo")
    @ResponseBody
    public Object searchFaultTypePage(EnergyVo vo) throws Exception {
        Pagination page = oilPriceService.searchRefuelQuery(vo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 
     * @param vo
     * @return
     * @author:chenl
     * @return 
     * @email:370238764@qq.com
     * @创建日期:2016-9-5
     * @功能说明：油价信息查询
     */
    @RequestMapping("/saveEnergyPriceSet")
    @ResponseBody
    public Object saveEnergyPriceSet(AppOilPriceEntity entity) throws Exception {
    	if(entity.getId().isEmpty()){
    		entity.setId(UtilString.getUUID());
        	SysUserEntity user = this.getCurrentUser().getUser();
        	entity.setCrtTime(new Date());
        	entity.setCrtUser(user.getAcctName());
        	oilPriceService.addEnergyPriceSet(entity);
    	}else{
    		SysUserEntity user = this.getCurrentUser().getUser();
    		entity.setUpdateTime(new Date());
    		entity.setUpdateUser(user.getAcctName());
    		oilPriceService.updateEnergyPriceSet(entity);
    	}
    	return this.getReturnResult(null);
    }
    
    /**
     * 
     * @param id
     * @return
     * @author:chenl
     * @return 
     * @email:370238764@qq.com
     * @创建日期:2016-9-6
     * @功能说明：通过id查找整条记录
     */
    @RequestMapping("/getEnergyInfoById")
    @ResponseBody
    public Object getEnergyInfoById(String id) throws Exception {
    	AppOilPriceEntity entity =(AppOilPriceEntity) oilPriceService.getEnergyInfoById(id);
        return this.getReturnResult(entity);
   }  
    
    /**
     * 
     * @param id
     * @return
     * @author:chenl
     * @return 
     * @email:370238764@qq.com
     * @创建日期:2016-9-6
     * @功能说明：通过id删除整条记录
     */
    @RequestMapping("/delEnergyInfo")
    @ResponseBody
    public Object delEnergyInfo(String id) throws Exception {
    	oilPriceService.delEnergyInfo(id);
        return this.getReturnResult(null);
   }
    
    /**
     * 导出车辆信息excel
     * @param dataVo
     * @param response
     * @throws Exception
     * @author:chenl
     * @email:370238764@qq.com
     */
    @RequestMapping("/exportEnergyInfoExcel")
    public void exportCarInfoExcel(EnergyExportVo dataVo, HttpServletResponse response) throws Exception {
    	List<BaseEntity> list = oilPriceService.getEnergyInfoList(dataVo);
    	ExportUtil.exportFiles(Arrays.asList(tableHeaderNames), Arrays.asList(tableHeaderFields), list, response, "excel", "energyInfo", "能源价格信息");
    }
    
    
    /**
     * 导出车辆信息excel
     * @param dataVo
     * @param response
     * @throws Exception
     * @author:chenl
     * @email:370238764@qq.com
     */
    @RequestMapping("/exportEnergyInfoPdf")
    @ResponseBody
    public void exportCarInfoPdf(EnergyExportVo dataVo, HttpServletResponse response) throws Exception {
    	List<BaseEntity> list = oilPriceService.getEnergyInfoList(dataVo);
    	ExportUtil.exportFiles(Arrays.asList(tableHeaderNames), Arrays.asList(tableHeaderFields), list, response, "pdf", "energyInfo", "能源价格信息");
    }
    
    
    
}
